package com.taoym.voucher.admin.controller;

import com.taoym.voucher.admin.entity.dto.XcxAddActivityDTO;
import com.taoym.voucher.admin.entity.vo.XcxActivityVO;
import com.taoym.voucher.admin.service.XcxActivityService;
import com.taoym.voucher.common.response.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @coder taoym
 * @datetime 2021/7/1 16:06
 * @desc
 */
@RestController
@RequestMapping("/xcx/activity")
@Api(tags = "活动信息控制器")
@Validated
public class XcxActivityController {

    @Autowired
    private XcxActivityService xcxActivityService;

    @ApiOperation("查询活动列表")
    @GetMapping("/list")
    public Response<List<XcxActivityVO>> listActivities() {
        return Response.success(xcxActivityService.listActivities());
    }

    @ApiOperation("删除活动信息")
    @GetMapping("/delete")
    public Response<Boolean> deleteActivity(@RequestParam @NotNull(message = "活动编号不能为空") Integer actId) {
        return Response.success(xcxActivityService.deleteActivity(actId));
    }

    @ApiOperation("添加活动信息")
    @PostMapping("/add")
    public Response<Integer> addActivity(@RequestBody @Valid XcxAddActivityDTO data) {
        return Response.success(xcxActivityService.addActivity(data));
    }
}
